import {request} from '../../../utils/requestUtils';
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    lines:[],
    typeShow:false,
    imageURL:'https://pic.rmb.bdstatic.com/bjh/3ea32057ba5/250227/7d2fddd7117282e610c2d058ee5bd236.jpeg'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 新增单位弹窗 
    addOrderShow(data) {
      console.log('data', data)
      this.setData({
        lines:data
      })
      this.setData({
        typeShow:true
      })
    },
    // 关闭弹窗
    onClose(){
      this.setData({
        typeShow:false
      })
    },
    onCarNumChange(event){
      console.log('event', event)
      const {detail} = event
      const {id, index} = event.target.dataset
      this.setData({
        [`lines[${index}].carNum`]: detail
      })
    },
    // 跳转商品详情
    toOrderDetails(e){
      console.log('e',e)
      if(!e.target.dataset.carnum || e.target.dataset.carnum == 0){
        wx.showToast({
          title: '购买数量不能为0',
          icon: 'none'
        })
        return;
      }
      wx.navigateTo({
        url: '/pages/customer_pay/index?good='+ encodeURIComponent(JSON.stringify({
          productId: e.target.dataset.prodid,
          carNum: e.target.dataset.carnum
        }))
      })
    },
    // 保存单位
    async save(){
      const result = await request({
        url: '/merchant/bus/unit',
        method: "POST",
        data: {...this.data.form, ...{stallId:''}}
      });
      if(result.data.code == 200){
        this.setData({
          typeShow:false
        })
      }
    }
  }
})